package com.sofar.gems.framework.controller;

import com.sofar.gems.framework.entity.Ces;
import com.sofar.gems.framework.service.ICesService;
import com.sofar.gems.framework.service.impl.CesServiceImpl;
import com.sofar.gems.framework.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author FENGZENG
 * @ClassName CesController
 * @date 2021/9/13 22:15
 * @Description TODO
 */
@Controller
public class CesController {

    @Autowired
    private ICesService cesService;

    @RequestMapping("/test")
    public ModelAndView test() {
        ModelAndView mav = new ModelAndView("/test");

        Ces ces = cesService.getById(1);

        mav.addObject("ces", ces);

        return mav;
    }


    @GetMapping("/insertCes")
    @ResponseBody
    public R<String > insertCes() {
        Ces ces = new Ces();

        ces.setUsername("ces" + new Random().nextInt(100));
        ces.setPassword("123456");
        ces.setCreateTime(new Date());

        cesService.save(ces);
        return R.success("插入成功");
    }

}
